package com.example.cpms.service.impl;

import com.example.cpms.entity.HouseHold;
import com.example.cpms.mapper.HouseHoldMapper;
import com.example.cpms.service.HouseHoldService;
import com.example.cpms.utils.PageBean;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HouseHoldServiceImpl implements HouseHoldService {

    @Autowired
    private HouseHoldMapper houseHoldMapper;


    /**
     * 删除楼宇
     * @param id
     */
    @Override
    public void delete(Integer id) {
        houseHoldMapper.deleteById(id);
    }


    /**
     * 新增楼宇
     * @param houseHold
     */
    @Override
    public void add(HouseHold houseHold) {
        houseHoldMapper.insert(houseHold);
    }

    /**
     * 编辑楼宇
     * @param houseHold
     */
    @Override
    public void update(HouseHold houseHold) {
        houseHoldMapper.update(houseHold);
    }


    /**
     * 分页查询
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @Override
    public PageBean page(Integer page, Integer pageSize,String name,String idCart,String phone) {
        PageHelper.startPage(page,pageSize);//使用PageHelper分页查询插件
        List<HouseHold> houseHoldList = houseHoldMapper.list(name,idCart,phone); //从数据库获取列表数据
        Page<HouseHold> p = (Page<HouseHold>) houseHoldList; //强转
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }
}
